#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5+10;

map <int,int> m[MAXN];

map <int,int> :: iterator it;

int fa[MAXN],siz[MAXN],n,q;

int gf(int x){return fa[x] == x?x : fa[x] = gf(fa[x]);}

void uni(int x,int y){
	int fx = gf(x),fy = gf(y);
	if(fx == fy) return;
	if(siz[fx] > siz[fy]) swap(fx,fy);
	for(it = m[fx].begin();it != m[fx].end();it++) m[fy][it->first] += it->second;
	siz[fy] += siz[fx]; fa[fx] = fy; siz[fx] = 0;
}
int main (){
	scanf("%d %d",&n,&q);
	for(int i = 1;i <= n;i++) fa[i] = i,siz[i] = 1;
	for(int i = 1;i <= n;i++){
		int f;scanf("%d",&f);
		m[i][f]++;
	}
	while(q--){
		int op,x,y; scanf("%d %d %d",&op,&x,&y);
		if(op == 1) uni(x,y);
		else printf("%d\n",m[gf(x)][y]);
	}
	return 0;
}
